﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace DFGK.IRepository
{
    public interface IBaseRepository<TEntity> where TEntity : class
    {
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        void AddEntity(TEntity obj);

        /// <summary>
        /// 批量添加
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        void AddEntityList(List<TEntity> list);

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        void DelEntity(TEntity obj);

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        void DelEntityList(List<TEntity> list);

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        void UpdEntity(TEntity obj);

        /// <summary>
        /// 异步修改
        /// </summary>
        /// <param name="eneity"></param>
        /// <returns></returns>
        Task UpdateAsync(TEntity eneity);
        /// <summary>
        /// 批量修改
        /// </summary>
        /// <param name="list"></param>
        void UpdEntityList(List<TEntity> list);

        /// <summary>
        /// 获取全部信息
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        List<TEntity> GetAllEntityList();

        /// <summary>
        /// 获取全部数据
        /// </summary>
        /// <returns></returns>
        IQueryable<TEntity> GetEntityAll();

        /// <summary>
        /// 去除跟踪状态获取全部数据
        /// </summary>
        /// <returns></returns>
        IQueryable<TEntity> GetEntityAlls();

        /// <summary>
        /// 根据条件查询全部数据
        /// </summary>
        /// <returns></returns>
        IQueryable<TEntity> GetEntityWhereAll(Expression<Func<TEntity, bool>> where);

        /// <summary>
        /// 分页
        /// </summary>
        /// <typeparam name="OrderField">排序条件类型</typeparam>
        /// <param name="expression">查询条件</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="pageSize">每页显示的最大条数</param>
        /// <param name="toalCount">out 总条数</param>
        /// <param name="orderField">按什么排序</param>
        /// <param name="isAsc">正？反序</param>
        /// <returns></returns>
        IQueryable<TEntity> GetEntityAll<OrderField>(int pageIndex, int pageSize, out int totalCount, Expression<Func<TEntity, OrderField>> orderField, Expression<Func<TEntity, bool>> expression = null, bool isAsc = true);

        /// <summary>
        /// D.分页
        /// </summary>
        /// <typeparam name="OrderField"></typeparam>
        /// <param name="list"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="orderField"></param>
        /// <param name="isAsc"></param>
        /// <returns></returns>
        IQueryable<TEntity> GetEntityAlls<OrderField>(IQueryable<TEntity> list, int pageIndex, int pageSize,out int totalCount, Expression<Func<TEntity, OrderField>> orderField, bool isAsc = true);

        /// <summary>
        /// 根据主键获取对象信息：long类型
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        TEntity? QueryEntityById(long Id);

        /// <summary>
        /// 根据条件获取对象信息
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        TEntity? QueryEntityWhere(Expression<Func<TEntity, bool>> where);
        /// <summary>
        /// 异步方法获取对象
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        Task<TEntity> GetAsync(Expression<Func<TEntity, bool>> where);


        /// <summary>
        /// 去除跟踪状态判断信息是否存在
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        TEntity? QueryIsEntityWhere(Expression<Func<TEntity, bool>> where);
    }
}
